home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-06-27 | 9.4 KB | 383 lines | [TEXT/MPS ] |
- { *** =================================================== ***
-
- Purpose: Terminal tool's main scripting code
- module. Basically used to convert private
- structure values into strings (e.g., TMGetConfig).
-
- Module : tscr.p
-
- Authors: Craig Hotchkiss, Alex Kazim, Byron Han,
- Carol Lee
- Apple Computer, Inc.
- Networks & Communications
- 20525 Mariani Drive
- Cupertino, CA 95014
-
- Version : 1.0d1
-
- Date : 9.may.89
-
- History :
- 9.may.89 Creation date
-
-
- ©1989 Apple Computer, Inc. All Rights Reserved.
- This software is proprietary to Apple Computer, Inc.
- It may not be copied, in whole or in part,
- without the written consent of Apple Computer, Inc.
-
- *** =================================================== *** }
-
-
-
-
- Unit TERMINALtscr;
-
-
- INTERFACE
-
-
- USES MemTypes,
- QuickDraw,
- OSIntf,
- ToolIntf,
- PasLibIntf,
- Lists,
- CRMSerialIntf,
- CRMIntf,
- CTBUtils,
- CMIntf,
- TMIntf,
- FTIntf,
- TerminalTool,
- TermGlobalUnit;
-
-
-
-
-
- FUNCTION tscrMAIN(hTerm: TermHandle; message: Integer;
- p1, p2, p3: LongInt) : LongInt;
-
-
- IMPLEMENTATION
-
-
-
- FUNCTION TMToolGetConfig(theProcID: Integer; theConfigPtr: Ptr;
- StrResID: Integer): Ptr;
- FORWARD;
- PROCEDURE GetPhrase(VAR theWorkString: Str255;
- VAR theWord: Str255; VAR theValue: Str255;
- VAR masterPosition: Integer);
- FORWARD;
- FUNCTION Uppercase(theValue: Str255): Str255;
- FORWARD;
- FUNCTION CheckTheSucker(theValue: Str255; StrResID: Integer): Integer;
- FORWARD;
- FUNCTION GetTheSOBIndex(theWord: Str255; StrResID: Integer): Integer;
- FORWARD;
- FUNCTION TMToolSetConfig(theProcID: Integer;
- theConfigPtr: Ptr; theStringPtr: Ptr; StrResID: Integer): LongInt;
- FORWARD;
-
-
-
-
- FUNCTION tscrMAIN(hTerm: TermHandle; message: Integer;
- p1, p2, p3: LongInt) : LongInt;
-
- { This function shares the success or failed message with the
- toolbox, and also points the toolbox in the right direction
- with it's message code (defined in TerminalTool.p) }
-
- VAR
- StrResID: Integer;
- tempProcID: Integer;
- tempConfigPtr: Ptr;
-
- tempPrivatePtr: TERMINALPrivatePtr;
- saved: SignedByte;
-
- mBTemp: Str255;
- mBString: Str255;
- BEGIN
- tscrMAIN := 0;
- saved := HGetState(Handle(hTerm));
- HLock(Handle(hTerm));
-
- { These are passed to the 'get' and 'set' routines. }
- tempPrivatePtr := TERMINALPrivatePtr(hTerm^^.tmPrivate);
- StrResID := Integer(tempPrivatePtr^.currentLanguage);
- tempProcID := hTerm^^.procID;
- tempConfigPtr := hTerm^^.config;
-
- HSetState(Handle(hTerm), saved);
-
- CASE message OF
- TMMgetMsg:
- tscrMAIN := LongInt(
- TMToolGetConfig(tempProcID,
- tempConfigPtr, StrResID));
- TMMsetMsg:
- tscrMAIN :=
- TMToolSetConfig(tempProcID,
- tempConfigPtr, Ptr(p1), StrResID);
- END; { CASE }
- END;
-
-
- FUNCTION TMToolGetConfig(theProcID: Integer; theConfigPtr: Ptr;
- StrResID: Integer): Ptr;
-
- { This function returns a pointer to my configuration string, that
- gets set up accordingly to current field values from my structure.
- The string is built here using string concats. It's assumed for
- this tool that the delimiter throughout the string is a space. }
-
- VAR
- pConfigStr : Ptr;
- pConfig : TERMINALPtr;
- tempStr : Str255;
- lastPoint : Integer;
- i : Integer;
- theStrPtr : StringPtr;
- storeStr : Str255;
- tempPtr : StringPtr;
- BEGIN
- pConfig := TerminalPtr(theConfigPtr);
-
- { gets string token and sets it's value according to
- how the fields are set in my private data structure,
- adding a space separator between item.
- String when finished:
- WORD value WORD value WORD value }
-
- GetIndString(tempStr, StrResID, onlineBoolean);
- storeStr := Concat(tempStr, ' ');
- IF pConfig^.onlineBoolean THEN
- GetIndString(tempStr, StrResID, trueID)
- ELSE
- GetIndString(tempStr, StrResID, falseID);
- storeStr := Concat(storeStr, tempStr, ' ');
-
-
-
- GetIndString(tempStr, StrResID, screen132Boolean);
- storeStr := Concat(storeStr, tempStr, ' ');
- IF pConfig^.screenWidth THEN
- GetIndString(tempStr, StrResID, trueID)
- ELSE
- GetIndString(tempStr, StrResID, falseID);
- storeStr := Concat(storeStr, tempStr, ' ');
-
-
-
- GetIndString(tempStr, StrResID, cursorStyleBoolean);
- storeStr := Concat(storeStr, tempStr, ' ');
- IF pConfig^.cursorStyle THEN
- GetIndString(tempStr, StrResID, trueID)
- ELSE
- GetIndString(tempStr, StrResID, falseID);
- storeStr := Concat(storeStr, tempStr);
-
- storeStr := Concat(storeStr, Chr($0));
-
- pConfigStr := NewPtrClear(SIZEOF(storeStr)); { allocate pointer }
-
- { move my Str255 (now zero terminated) to the pointer location.
- The + 1 makes sure that the length byte (Str255) is not included. }
-
- BlockMove(Ptr(Ord4(@storeStr) + 1), pConfigStr,
- Length(storeStr));
- TMToolGetConfig := pConfigStr;
- END;
-
-
-
- PROCEDURE GetPhrase(VAR theWorkString: Str255;
- VAR theWord: Str255; VAR theValue: Str255;
- VAR masterPosition: Integer);
-
- { Part of my simple decoder that rips apart the current config
- string, returning the first word and it's associated value.
- It also deletes both from the config string since the length
- of the string determines whether we are finished. }
-
- VAR
- spacePos: Integer;
- BEGIN
- spacePos := Pos(' ', theWorkString);
- theWord := Copy(theWorkString, 1, (spacePos - 1));
- Delete(theWorkString, 1, spacePos);
- masterPosition := masterPosition + (Length(theWord) + 1);
- spacePos := Pos(' ', theWorkString);
- IF (spacePos <> 0) THEN
- BEGIN
- theValue := Copy(theWorkString, 1, (spacePos - 1));
- Delete(theWorkString, 1, spacePos);
- END
- ELSE
- BEGIN
- theValue := Copy(theWorkString, 1, Length(theWorkString));
- Delete(theWorkString, 1, Length(theWorkString));
- END;
- masterPosition := masterPosition + (Length(theValue) + 1);
- END;
-
-
-
-
- FUNCTION Uppercase(theValue: Str255): Str255;
- { Added to ensure case insensitivity. }
- VAR
- stringLength: Integer;
- tempNumber: Integer;
- tempChar: Char;
- i: Integer;
- BEGIN
- stringLength := Length(theValue);
- FOR i := 1 to stringLength DO
- BEGIN
- tempNumber := Ord(theValue[i]);
- IF tempNumber > 91 THEN
- BEGIN
- tempNumber := tempNumber - 32;
- theValue[i] := Chr(tempNumber);
- END;
- END;
- Uppercase := theValue;
- END;
-
-
- FUNCTION CheckTheSucker(theValue: Str255; StrResID: Integer): Integer;
- { Checks the value returned to make sure it's within range. If
- not, the entire config fails. }
- VAR
- trueString: Str255;
- falseString: Str255;
- tempString: Str255;
-
- mBString: Str255;
- mBTemp: Str255;
- BEGIN
- CheckTheSucker := 2;
- theValue := Uppercase(theValue);
- GetIndString(tempString, StrResID, trueID);
- trueString := Uppercase(tempString);
- GetIndString(tempString, StrResID, falseID);
- falseString := Uppercase(tempString);
-
- IF theValue = falseString THEN
- CheckTheSucker := 0;
- IF theValue = trueString THEN
- CheckTheSucker := 1;
- {
- NumToString(LongInt(theItem), mBTemp);
- mBString := Concat('The string is: ', mBTemp, 'PROOF');
- DebugStr(mBString);
- }
- END;
-
-
- FUNCTION GetTheSOBIndex(theWord: Str255; StrResID: Integer): Integer;
-
- { This function checks the phrase returned to make sure it matches
- one of my resource strings. If not, the entire config fails. }
-
- VAR
- Phrase1String: Str255;
- Phrase2String: Str255;
- Phrase3String: Str255;
- tempString: Str255;
- BEGIN
- GetTheSOBIndex := 4;
- theWord := Uppercase(theWord);
- GetIndString(tempString, StrResID, onlineBoolean);
- Phrase1String := Uppercase(tempString);
- GetIndString(tempString, StrResID, screen132Boolean);
- Phrase2String := Uppercase(tempString);
- GetIndString(tempString, StrResID, cursorStyleBoolean);
- Phrase3String := Uppercase(tempString);
-
- IF theWord = Phrase1String THEN
- GetTheSOBIndex := 1;
- IF theWord = Phrase2String THEN
- GetTheSOBIndex := 2;
- IF theWord = Phrase3String THEN
- GetTheSOBIndex := 3;
- END;
-
-
-
- FUNCTION TMToolSetConfig(theProcID: Integer;
- theConfigPtr: Ptr; theStringPtr: Ptr; StrResID: Integer): LongInt;
-
- { This main guy rips up the current config string in order to set
- values in this tool's private structure. Currently it's function
- assumes a space delimited string and it does not utilize the script
- manager's tokenizing functions. The variable 'masterPosition'
- is used here to return the approx. character position of any failures
- that may be encountered. }
-
- VAR
- theCharCount: Integer;
- theWordIndex: Integer;
- theValueIndex: Integer;
- masterPosition: Integer;
- tempString: Str255;
- theWorkString: Str255;
- theWord: Str255;
- theValue: Str255;
- pConfig: TerminalPtr;
- theControlArray: PACKED ARRAY [0..511] of Char;
- BEGIN
- pConfig := TerminalPtr(theConfigPtr);
-
- { Ugliness! Here I assume the CString is less than 512 chars long.
- I really should exit otherwise. }
-
- BlockMove(theStringPtr, Ptr(Ord4(@theControlArray)), 512);
- theCharCount := Scaneq(512, Chr(0), theControlArray);
- IF theCharCount < 255 THEN
- BlockMove(
- Ptr(Ord4(@theControlArray)),
- Ptr(Ord4(@theWorkString) + 1), theCharCount);
- theWorkString[0] := Char(theCharCount);
-
- masterPosition := 0; { Init the char pos counter }
-
- WHILE Length(theWorkString) > 0 DO
- BEGIN
- GetPhrase(theWorkString, theWord, theValue,
- masterPosition);
- theWordIndex := GetTheSOBIndex(theWord, StrResID);
- theValueIndex := CheckTheSucker(theValue, StrResID);
- IF (theValueIndex > 1) OR (theWordIndex > 3) THEN
- BEGIN
- TMToolSetConfig := LongInt(masterPosition);
- Exit(TMToolSetConfig);
- END;
- CASE theWordIndex OF
- onlineBoolean:
- pConfig^.onlineBoolean := Boolean(theValueIndex);
- screen132Boolean:
- pConfig^.screenWidth := Boolean(theValueIndex);
- cursorStyleBoolean:
- pConfig^.cursorStyle := Boolean(theValueIndex);
- OTHERWISE
- BEGIN
- TMToolSetConfig := 4000;
- Exit(TMToolSetConfig);
- END;
- END; { CASE }
- END; { WHILE }
-
- TMToolSetConfig := 0;
- END;
-
-
-
-
-
- END.